//
//  ViewForSectionHeader.m
//  ProjectA
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "ViewForSectionHeader.h"
#import "AppMacro.h"
#import "NSString+HeightLabel.h"
#import "ModelForSectionHeader.h"
#import <UIImageView+WebCache.h>
@interface ViewForSectionHeader ()
@property (nonatomic, strong) UIImageView *avatar_l;
@property (nonatomic, strong) UILabel *name;
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UILabel *text_Model;
@end

@implementation ViewForSectionHeader
- (void)dealloc {

    [_avatar_l release];
    [_name release];
    [_view release];
    [_text_Model release];
    [super dealloc];

}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.avatar_l = [[UIImageView alloc] init];
        [self.contentView addSubview:self.avatar_l];
        [_avatar_l release];
        
        self.name = [[UILabel alloc] init];
        [self.contentView addSubview:self.name];
        [_name release];
        
        self.view = [[UIView alloc] init];
        [self.contentView addSubview:self.view];
        [_view release];
        
        self.text_Model = [[UILabel alloc] init];
        [self.contentView addSubview:self.text_Model];
        [_text_Model release];
    }
    return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    // 布局子控件
    self.avatar_l.frame = CGRectMake(20, 20, 50, 50);
    self.avatar_l.layer.cornerRadius = 25;
    self.avatar_l.layer.masksToBounds = YES;
    
    self.name.frame = CGRectMake(30 + 40 + 10, 35, self.frame.size.width - 50, 20);
    self.name.font = [UIFont boldSystemFontOfSize:15];
    
    self.view.frame = CGRectMake(20, 20 + 50 + 20, self.frame.size.width - 40, 1);
    
    self.text_Model.frame = CGRectMake(20, 20 + 50 + 20 + 1 + 20, self.frame.size.width - 40, [NSString heightForLabel:self.text_Model.text withWidth:self.frame.size.width - 40 withEdge:0 withFontOfSize:17]);
    self.text_Model.numberOfLines = 0;
    // 设置颜色
    
    [UIView setColorWithView:self.view nightColor:L_COLOR_WHITE dayColor:L_COLOR_LIGHTGRAY];
    [UIView setColorWithLabelText:self.name nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.text_Model nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelView:self.text_Model nightColor:RGBA(52, 52, 52, 1) dayColor:L_COLOR_CLEAR];
    
}

- (void)passData:(ModelForSectionHeader *)model {
    
    
    [self.avatar_l sd_setImageWithURL:[NSURL URLWithString:[model.user objectForKey:@"avatar_l"]] placeholderImage:[UIImage imageNamed:@"iconfont-zhanweitu"]];
    self.name.text = [model.user objectForKey:@"name"];
    self.text_Model.text = model.text;
 
}
@end
